﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using Models;
using System.Data;
using System.Web;
using System.Collections.Generic;

public partial class HxGoodsList : AdminBase
{

    private string _SID;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.Params["SID"]))
        {
            _SID = HttpContext.Current.Request.QueryString["SID"];
        }
        if(!IsPostBack)
        grdbind();
    }

    public void grdbind()
    {
        using (Entities bll = new Entities())
        {
            var StoreUser = bll.User.Where(p => p.UPower == _SID);
            List<string> _StoreUser = new List<string>();
            foreach (var SU in StoreUser) {
                _StoreUser.Add(SU.UOpenID);
            }

            var Bpl = from p in bll.S_Ordered.OrderByDescending(p=>p.OHxTime)
                       where _StoreUser.Contains(p.OHxOpenId)
                       select p;
            //if (txtUtel.Text.Trim() != "")
            //{
            //    Bpl = Bpl.Where(p => p.UTel.Contains(txtUtel.Text.Trim()) || p.UNickName.Contains(txtUtel.Text.Trim()) || p.UTrueName.Contains(txtUtel.Text.Trim()));
            //}

            //PagedDataSource pds = new PagedDataSource();
            //pds.DataSource= Bpl.ToList();
            //pds.AllowPaging = true;
            AspNetPager1.RecordCount = Bpl.Count(); //记录总数；
            //pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex;
            //pds.PageSize = AspNetPager1.PageSize;
            this.rptList.DataSource = Bpl.Skip((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize).ToList();  //这里好像一定要Tolist();不然会有点错误；;
            this.rptList.DataBind();
        }
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {   //当页面页数改变时，执行这个方法；
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        grdbind();
    }
    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int id = Convert.ToInt32(((Label)e.Item.FindControl("lb_id")).Text);
        Entities bll = new Entities();
        L_Tags model = bll.L_Tags.First(p => p.TID == id);
        switch (e.CommandName.ToLower())
        {
            case "del":
                bll.L_Tags.Remove(model);
                break;
        }
        bll.SaveChanges();
        grdbind();

    }

}

